package com.cy.law.activemq;

import com.cy.law.db.dao.DeviceGpsDao;
import com.cy.law.db.entity.DeviceGps;
import com.cy.law.utils.XmlUtil;
import com.cy.law.vo.GpsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Transactional(rollbackFor = Exception.class)
@Component
@Slf4j
public class GpsConsumer {
    @Autowired
    DeviceGpsDao deviceGpsDao;

    @JmsListener(destination = "mag.gps.topic")
    public void receiveGis(String xml) {
//        log.info("device active msg - xml:{}", xml);
        GpsVO gpsVO = XmlUtil.toObject(xml, GpsVO.class);
        DeviceGps deviceGps = new DeviceGps();
        BeanUtils.copyProperties(gpsVO, deviceGps);
        deviceGpsDao.save(deviceGps);
    }
}
